import { useNavigate } from 'react-router-dom'
import { useEffect, useState } from 'react'
import { getweicsc, getUser2Djm } from '../api/api'
import '../weicsc.css'
function ShiChang() {
  const [list, setList] = useState([])
  const navigate = useNavigate()
  const [users, setsuers] = useState({})
  let user = sessionStorage.getItem('user')


  //获取数据
  useEffect(() => {
    getweics()
    getUser2Djm(user).then((res) => {
      setsuers(res.data)
      console.log(res.data)
    })
  }, [])
  function getweics() {
    getweicsc().then((res) => {
      console.log(res)
      if (res.code == 200) {
        setList([...res.data])
        console.log(res.data);
      }
    })
  }
  //路由跳转
  function func(url, id) {
    console.log(url)
    navigate(url, {
      state: {
        id: id,
      },
    })
  }
  return (
    <div  style={{textAlign:'center'}}>
      <div className="toble">
        彩市场{''}
        <span
          id="fanbu"
          onClick={() => {
            func('/fanbu')
          }}
        >
          发布
        </span>
      </div>
      <div className="nro">
        <div>
          {list.map((item) => {
            return (
              <div key={item.id}>
                <div >
                  <img src={item.toxi} className="toxi"></img>
                  <span className="name">{item.name}</span>
                  <span className="sjian">{item.sjian}</span>
                  <span className="jiang">{item.jiang}</span>
                </div>
                <div className="tupian" >
                  <img
                    src={item.img}
                    onClick={() => {
                      func('/details', item.id)
                    }}
                  ></img>
                  <img src={item.image}></img>
                  <img src={item.urlimg}></img>
                </div>
                <div>
                  <span className="leixin">{item.leixin}</span>
                  <span>{item.tagex}</span>
                  <br></br>
                  <span>{item.tagex1}</span>
                </div>
              </div>
            )
          })}
        </div>
      </div>
    </div>
  )
}

export default ShiChang
